from page.focus_project_page import FocusProjectPage
from common.page import XPATH
import random as r
from page.common_tools import CommonTools
from time import sleep


class FocusWorkPage(FocusProjectPage, CommonTools):

    def release_work(self):
        self.find_button("发布").click()
        self.find_static_text("请输入标题", contains_flag=1).click()
        self.find_static_text("请输入标题", contains_flag=1).send_keys("App面授作业自动化测试%d" % r.randint(100, 999))
        self.find_static_text('开始时间').click()
        self.find_button(string="确定",contains_flag=1).click()
        self.find_static_text('截止时间').click()
        sleep(1)
        self.get_frame_center_and_swipe((XPATH, "//XCUIElementTypePickerWheel[1]"))
        self.find_button(string="确定",contains_flag=1).click()
        # self.find_static_text('关联课程').click()
        # self.find_static_text('培训项目').click()
        # self.find_button(string="确定",contains_flag=1).click()
        self.find_static_text("请输入作业描述", contains_flag=1).click()
        self.find_static_text("请输入作业描述", contains_flag=1).send_keys("那种不知敬畏的人是从不在人格上反省自己的。如果说�知耻近乎勇�，那么，这种人因为不知耻便显出一种卑怯的放肆。只要不受惩罚，他敢于践踏任何美好的东西，包括爱情、友谊、荣誉，而且内心没有丝毫不安。这样的人尽管有再多的艳遇，也没有能力真正爱一回；结交再多的哥们，也体味不了友谊的纯正；获取再多的名声，也不知什么是光荣。不相信神圣 的人，必被世上一切神圣的事物所抛弃。。。。")
        self.find_button(string="确认",contains_flag=1).click()
        sleep(2)
        self.find_button(string="common back dark icon",contains_flag=1).click()
        self.find_button(string="数学班").click()


    def submit_work(self, work_content="这是提交作业的内容。。。。"):
        self.find_static_text("未提交").click()
        sleep(2)
        self.find_button("提交").click()
        sleep(2)
        self.find_static_text("查看详情").click()
        self.find_button("我同意").click()
        # self.find_element(XPATH, "//XCUIElementTypeTextField[@value='输入作业标题']").send_keys("这是提交作业的标题。。。")
        self.find_element(XPATH, "//XCUIElementTypeTextField[contains(@value,'输入作业标题')]").send_keys("这是提交作业的标题。。。")
        self.find_static_text("输入作业内容", contains_flag=1).click()
        self.find_static_text("输入作业内容", contains_flag=1).send_keys(work_content)
        sleep(2)
        self.get_frame_center_and_click(self.find_button("提交"), flag=0)
        self.find_button(string="返回",contains_flag=1).click()
        sleep(1)
        self.find_button(string="common back dark icon",contains_flag=1).click()
        self.find_button(string="数学班").click()


if __name__ == '__main__':
    test = FocusWorkPage()
    test.enter_project()
    test.enter_tools("作业")
    # test.release_work()
    # test.submit_work()
    test.submit_work(''.join(["一千个字" for x in range(250)]))  # 提交一千字的作业
